/**
 * This file is part of the CAKIS project.
 * 
 * Copyright (c) 2009-2010 - Florian Arndt, Christian Kerl
 * 
 * @license GNU Lesser General Public License v3 <http://www.opensource.org/licenses/lgpl-3.0.html>
 * @since   09.05.2010
 * @version SVN: $Id: DateToStringAdapter.java 115 2010-05-09 12:30:12Z christian-kerl@web.de $
 */
package org.cakis.server.service.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.bind.annotation.adapters.XmlAdapter;

/**
 * DateToStringAdapter marshals a {@link Date} to a {@link String}.
 *
 * @author Christian Kerl
 */
public class DateToStringAdapter extends XmlAdapter<String, Date> {
    private static final String DateFormatString = "yyyy-MM-dd HH:mm:ss";

    @Override
    public String marshal(Date date) throws Exception {
        return getDateFormat().format(date);
    }

    @Override
    public Date unmarshal(String string) throws Exception {
        return getDateFormat().parse(string);
    }

    private DateFormat getDateFormat() {
        return new SimpleDateFormat(DateFormatString);
    }
}
